package servlet;

import service.CardServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import com.sample.Card;

@WebServlet(urlPatterns = "/ListView_Servlet")
public class ListView_Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,NullPointerException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        CardServiceImpl cardService = new CardServiceImpl();
        List<Card> list=cardService.list();
        request.getSession().setAttribute("list",list);
        String status=request.getParameter("status");
        String change="";
        if (status==null) {
            change="";
        }else if (status.equals("启用")){
            change="启用成功";
        }else if (status.equals("禁用")){
            change="禁用成功";
        }

        request.setAttribute("change",change);
        request.getRequestDispatcher("item/listView.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
